package com.kelaite.procurement.repository;

import java.util.Date;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.kelaite.procurement.entity.TPurchaseOrder;

public interface PurchaseOrderRepository extends JpaRepository<TPurchaseOrder, Long>{
	
	@Query(value = "select currency from t_purchase_order where id = ?1", nativeQuery = true)
	public short findCurrencyByOrderId(Long purchaseOrderId);
	
	@Query(value = "select price from t_purchase_order where id = ?1", nativeQuery = true)
	public Float findPriceByOrderId(Long purchaseOrderId);
	
	@Modifying
	@Query(value = "update t_purchase_order o set o.evaluationTotalDesc =:evaluationTotalDesc,o.evaluationScore4 =:evaluationScore4,o.gmtUpdateTime =:gmtUpdateTime, o.updatedBy =:updatedBy where o.id =:id")
	public int updatePurchaseOrderEstimate(@Param("id") Long id,
			@Param("evaluationTotalDesc") String evaluationTotalDesc,
			@Param("evaluationScore4") Double evaluationScore4,
			@Param("gmtUpdateTime") Date gmtUpdateTime,
			@Param("updatedBy") String updatedBy);
	
	
	@Modifying
	@Query(value = "update t_purchase_order o set o.evaluationTotalDesc =:evaluationTotalDesc,o.evaluationScore2 =:evaluationScore2,o.evaluationScore3 =:evaluationScore3,o.evaluationScore4 =:evaluationScore4,o.evaluationScore5 =:evaluationScore5,o.gmtUpdateTime =:gmtUpdateTime, o.updatedBy =:updatedBy where o.id =:id")
	public int updatePurchaseOrderEstimateManyGrade(@Param("id") Long id,
			@Param("evaluationTotalDesc") String evaluationTotalDesc,
			@Param("evaluationScore2") Double evaluationScore2,
			@Param("evaluationScore3") Double evaluationScore3,
			@Param("evaluationScore4") Double evaluationScore4,
			@Param("evaluationScore5") Double evaluationScore5,
			@Param("gmtUpdateTime") Date gmtUpdateTime,
			@Param("updatedBy") String updatedBy);
}
